﻿using System;
using System.ComponentModel;
using System.Windows.Media;

namespace Esponce.Models
{
	public class ColorListItem : INotifyPropertyChanged
	{
		#region Construtctors
		public ColorListItem()
		{
		}

		public ColorListItem(Color color)
		{
			this.Name = ToHexString(color);
			this.Color = color;
		}

		public ColorListItem(string name, Color color)
		{
			this.Name = name;
			this.Color = color;
		}
		#endregion

		#region Public properties
		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				if (this.name != value)
				{
					this.name = value;
					OnPropertyChanged("Name");
				}
			}
		}
		private string name;

		public Color Color
		{
			get
			{
				return this.color;
			}
			set
			{
				if (this.color != value)
				{
					this.color = value;
					OnPropertyChanged("Color");
					OnPropertyChanged("Brush");
				}
			}
		}
		private Color color;

		public Brush Brush
		{
			get
			{
				return new SolidColorBrush(this.Color);
			}
		}

		public bool IsDefault
		{
			get
			{
				return this.isDefault;
			}
			set
			{
				if (this.isDefault != value)
				{
					this.isDefault = value;
					OnPropertyChanged("IsDefault");
				}
			}
		}
		private bool isDefault;
		#endregion

		#region Public methods
		protected string ToHexString(Color color)
		{
			return string.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.A, color.R, color.G, color.B);
		}

		public string ToHexString()
		{
			return ToHexString(this.Color);
		}

		public override string ToString()
		{
			return this.Name;
		}
		#endregion

		#region INotifyPropertyChanged Members
		public event PropertyChangedEventHandler PropertyChanged;
		protected virtual void OnPropertyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}
		#endregion
	}
}
